<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="utf-8">
<title>福利城堡-福利城堡</title>
<link href="../c/base.css" rel="stylesheet" type="text/css">
<link href="../c/toefl.css" rel="stylesheet" type="text/css">
<link href="../c/bootstrap.min.css" rel="stylesheet" type="text/css">
<script src="../j/jquery-2.1.0.js" type="text/javascript"
	charset="utf-8"></script>
<script src="../j/bootstrap.min.js" type="text/javascript"
	charset="utf-8"></script>
<script src="../layer/layer.js" type="text/javascript" charset="utf-8"></script>
<style>
.nowPage {
	color: red;
}
</style>
</head>

<script type="text/javascript">
	function searchCastle(mall_type, castle_type, pageNum, sort) {
		$("#mall_type").attr("value", mall_type);
		$("#castle_type").attr("value", castle_type);
		$("#pageNum").attr("value", pageNum);
		$("#sort").attr("value", sort);
		$("#castleForm").submit();
	}

	function payLimit(castle_id, status) {
		var loginMessage = $("#loginMessage").val();
		if (loginMessage == null || loginMessage == '') {
			layer.confirm('请先登录，再加入！！', {
				title : '提示'
			}, function(index) {
				window.parent.location = "toLogin";
				layer.close(index);
			}, function() {
				layer.close();
			});

		} else if (loginMessage == 'teacher') {
			layer.confirm('只有用户才可以加入，请使用用户账号登录！！', {
				title : '提示'
			}, function(index) {
				window.parent.location = "toLogin";
				layer.close(index);
			}, function() {
				layer.close();
			});
		} else if (status != '0') {
			layer.alert('课程已经结束报名了，看看别的吧！', function(index) {
				layer.close(index);
			});
		} else {
			$.ajax({
				url : 'isBuy',
				type : 'post',
				dateType : 'json',
				data : {
					castle_id : castle_id
				},
				success : function(result) {
					if (result) {
						layer.alert('你已经购买过这个课程，再看别的吧！', function(index) {
							layer.close(index);
						});
					} else {
						window.location = "toStepOne?castle_id=" + castle_id;
					}
				}
			})
		}
	}

	function getAttas(castle_id) {
		$.ajax({
			url : 'getAttas',
			dataType : 'json',
			type : 'post',
			data : {
				castle_id : castle_id
			},
			success : function(result) {
				var html = "";
				for (var i = 0; i < result.length; i++) {
					html += "<li><span class='flcb_cardDownloadZl'>资料"
							+ (i + 1)
							+ "</span><span class='flcb_cardDownloadBt'>"
							+ result[i].attachment_name
							+ "</span><a href='downloadAtta?attachment_id="
							+ result[i].attachment_id
							+ "' class='flcb_cardDownloadXz'>&nbsp;</a></li>";
				}
				$("#lili").html(html);
			}
		})

	}
	
	function phrase(teacher_id){
		var isPhrase = $("#isPhrase_" + teacher_id);
		var loginMessage = $("#loginMessage").val();
		var flag;
		if(isPhrase.text() == '赞'){
			flag = 1;
		}else if (isPhrase.text() == '取消'){
			flag = 2;
		}
		if (loginMessage == null || loginMessage == '') {
			layer.confirm('请先登录，再点赞！！', {
				title : '提示'
			}, function(index) {
				window.parent.location = "toLogin";
				layer.close(index);
			}, function() {
				layer.close();
			});

		} else if (loginMessage == 'teacher') {
			layer.confirm('只有用户才可以点赞，请使用用户账号登录！！', {
				title : '提示'
			}, function(index) {
				window.parent.location = "toLogin";
				layer.close(index);
			}, function() {
				layer.close();
			});
		} else {
			$.ajax({
				url : 'addOrDelPhrase',
				type : 'post',
				dataType : 'json',
				data : {
					teacher_id : teacher_id,
					flag : flag
				},
				success : function(result){
					if(result != null){
						$("#castleForm").submit();
					}
				}
				
			})
		}
		
	}
</script>

<body>
	<input type="hidden" name="loginMessage" id="loginMessage"
		th:value="${session.loginMessage}">
	<!-- 查询 -->
	<form action="toCastle" method="post" id="castleForm">
		<input type="hidden" name="mall_type" id="mall_type"
			th:value="${castleInfo.mall_type}"> <input type="hidden"
			name="castle_type" id="castle_type"
			th:value="${castleInfo.castle_type}"> <input type="hidden"
			name="pageNum" id="pageNum" th:value="${pageInfo.pageNum}"> <input
			type="hidden" name="sort" id="sort" th:value="${castleInfo.sort}">
	</form>

	<div class="container-fluid">
		<div class="openMenu">
			<div class="doc1180">
				<ul class="fn-clear" style="padding-left: 220px;">
					<li th:each="mallType:${mallTypes}"
						th:class="${castleInfo.mall_type == mallType.type_id} ? 'openMenuOn' : ''"
						style="float: left;"><a href="###"
						th:onclick="searchCastle([[${mallType.type_id}]], null, 1, 0)">[[${mallType.type_name}]]</a>
					</li>
				</ul>
			</div>
		</div>
		<div class="doc1180">
			<div class="castle">
				<div class="castleNote">您的等级越高、打折的力度越大啊，努力升级吧，亲！</div>
				<div class="castlePaixun">
					<dl class="fn-clear">
						<dt class="fn-clear">
							<a href="###"
								th:onclick="searchCastle([[${castleInfo.mall_type}]], null, 1, 0)"
								th:class="${castleInfo.castle_type == null} ? on : ''">全部课程</a>
							<a href="###" th:each="castleType:${castleTypes}"
								th:class="${castleInfo.castle_type == castleType.type_id} ? on : ''"
								th:onclick="searchCastle([[${castleInfo.mall_type}]], [[${castleType.type_id}]], 1, 0)">[[${castleType.type_name}]]</a>
						</dt>
						<dd class="fn-clear">
							<a href="###"
								th:onclick="searchCastle([[${castleInfo.mall_type}]], [[${castleInfo.castle_type}]], 1, 1)">按开始时间从近到远排列</a>
							<a href="###"
								th:onclick="searchCastle([[${castleInfo.mall_type}]], [[${castleInfo.castle_type}]], 1, 2)">按参与人数由多到少排列</a>
						</dd>
					</dl>
				</div>



				<ul th:each="castle:${pageInfo.list}">
					<li class="castlePic">
						<div class="castlePic_t">
							<a href="#"><img th:src="${castle.img_url}"></a>
						</div>
						<div class="castlePic_m">
							<span>RMB:<b>[[${castle.castle_pay}]]</b></span><span>RPB:<b>0</b></span>
						</div>
					</li>
					<li class="castleText">
						<div class="castleClass">[[${castle.class_title}]]</div>
						<div class="castleTime">
							上课时间：<span>[[${#dates.format(castle.start_date,
								'yyyy-MM-dd')}]]</span>到<span>[[${#dates.format(castle.end_date,
								'yyyy-MM-dd')}]]</span>&nbsp;&nbsp;&nbsp;&nbsp; 每周： <span
								style="color: green;">[[${castle.castle_cycle}]]</span>&nbsp;的&nbsp;<span
								style="color: red;">[[${#dates.format(castle.start_time,
								'HH: mm')}]]-[[${#dates.format(castle.end_time, 'HH: mm')}]]</span>上课
						</div>

						<div class="castleTech">
							<span class="first">主讲老师：</span> <span class="teacherPic"><img
								th:src="${castle.teacher.img_url}"></span> <span class="name">[[${castle.teacher.user_name}]]</span>
							<span class="zan"><a href="###"
								th:onclick="phrase([[${castle.teacher_id}]])"><img
									src="../i/icon_zan14x14.jpg"></a></span>
							<div th:switch="${castle.teacher_id}"
								th:if="${session.loginMessage == 'user'}">
								<div th:each="phrase : ${teacherPhrases}">
									<span class="zan" th:case="${phrase.teacher_id}"
										th:id="'isPhrase_' + ${castle.teacher_id}" style="width:40px">取消</span>
								</div>
								<span class="zan" th:case="*"
									th:id="'isPhrase_' + ${castle.teacher_id}" style="width:40px">赞</span>
							</div>
							<span class="zan"
								th:if="${session.loginMessage == 'teacher' || session.loginMessage == null}"
								th:id="'isPhrase_' + ${castle.teacher_id}">赞</span><span
								class="zanNum">（[[${castle.teacher.phrase_num}]]）</span>

						</div>
						<div class="castleXuyuan">适合学员：[[${castle.fit_person}]]</div>
						<div class="castleJieshao">[[${castle.castle_desc}]]</div>

					</li>
					<li class="castleRight">
						<div class="castleNum">
							<span>[[${castle.signup_num}]]人</span>参与
						</div>
						<div class="castleButton">
							<a th:href="@{/toCastleDetail(castle_id=${castle.castle_id})}">活动详情</a>
							<a href="###"
								th:onclick="payLimit([[${castle.castle_id}]], [[${castle.status}]])">我要加入</a>
							<a href="###" data-toggle="modal" data-target=".modal"
								th:onclick="getAttas([[${castle.castle_id}]])">资料下载</a>
						</div>
					</li>
				</ul>
			</div>
			<div class="pageList">
				<ul>
					<li th:if="${pageInfo.pageNum != 1}"><a href="###"
						th:onclick="searchCastle([[${castleInfo.mall_type}]],[[${castleInfo.castle_type}]], 1, [[${castleInfo.sort}]])">首页</a></li>
					<li th:each="pages:${pageInfo.navigatepageNums}"><a href="###"
						th:class="${pages == pageInfo.pageNum} ? nowPage : ''"
						th:onclick="searchCastle([[${castleInfo.mall_type}]],[[${castleInfo.castle_type}]], [[${pages}]], [[${castleInfo.sort}]])">【[[${pages}]]】</a></li>
					<li th:if="${pageInfo.pageNum != pageInfo.pages}"><a
						href="###"
						th:onclick="searchCastle([[${castleInfo.mall_type}]],[[${castleInfo.castle_type}]], [[${pageInfo.pages}]], [[${castleInfo.sort}]])">最后一页</a></li>
					<li th:if="${pageInfo.pageNum != 1}"><a href="###"
						class="pret"
						th:onclick="searchCastle([[${castleInfo.mall_type}]],[[${castleInfo.castle_type}]], [[${pageInfo.prePage}]], [[${castleInfo.sort}]])">上一页</a></li>
					<li th:if="${pageInfo.pageNum != pageInfo.pages}"><a
						href="###" class="next"
						th:onclick="searchCastle([[${castleInfo.mall_type}]],[[${castleInfo.castle_type}]], [[${pageInfo.nextPage}]], [[${castleInfo.sort}]])">下一页</a></li>
				</ul>
			</div>
		</div>
		<div class="modal fade" tabindex="-1" role="dialog">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title">课程资料</h4>
					</div>
					<div class="modal-body">
						<div class="flcb_cardDownload">
							<h3 class="flcb_cardDownloadT">课程资料下载</h3>
							<ul id="lili">

							</ul>

						</div>

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>

	</div>

</body>

</html>